// You have generated a new plugin project without
// specifying the `--platforms` flag. A plugin project supports no platforms is generated.
// To add platforms, run `flutter create -t plugin --platforms <platforms> .` under the same
// directory. You can also find a detailed instruction on how to add platforms in the `pubspec.yaml` at https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin-platforms.

import 'dart:async';

import 'package:flutter/services.dart';

class BankOcr {
  static const MethodChannel _channel = const MethodChannel('bank_ocr');

  static Future<String?> get platformVersion async {
    final String? version = await _channel.invokeMethod('getPlatformVersion');
    return version;
  }

  static Future<Map<String, dynamic>> get bankCardOcr async {
    try {
      final result = await _channel.invokeMethod('bankCardOcr');
      Map<String, dynamic> ocrResultMap = Map<String, dynamic>.from(result);
      return ocrResultMap;
    } catch (e) {
      if (e is PlatformException) {
        return Map<String, dynamic>.from(e.details);
      }
      return {"success": false, "message": e.toString()};
    }
  }

  static Future<dynamic> get init async {
    try {
      await _channel.invokeMethod('init');
      return null;
    } catch (e) {
      if (e is PlatformException) {
        return Map<String, dynamic>.from(e.details);
      }
      return {"success": false, "message": e.toString()};
    }
  }

  static Future<Map<String, dynamic>> bankCardOcrFromImagePath(
      String imagePath) async {
    try {
      final result = await _channel
          .invokeMethod('bankOcrFromImagePath', {'imagePath': imagePath});
      Map<String, dynamic> ocrResultMap = Map<String, dynamic>.from(result);
      return ocrResultMap;
    } catch (e) {
      if (e is PlatformException) {
        return Map<String, dynamic>.from(e.details);
      }
      return {"success": false, "message": e.toString()};
    }
  }
}
